package pen_exam.weipinhui_2024_03_30;

public class Class01_DeskWork {
    static volatile int desk = 0;
    public static void makeDesk() throws InterruptedException {
        desk++;
        System.out.println("做一张桌子");
        Thread.sleep(2000);
    }
    public static void paint() throws InterruptedException {
        desk--;
        System.out.println("paint");
        Thread.sleep(1000);
    }

    public static void main(String[] args) {
        Thread A = new Thread(()->{
            while(true){
                try {
                    makeDesk();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread B = new Thread(()->{
            while (true){
                try {
                    if(desk > 0){
                        paint();
                    }else{
                        Thread.sleep(10);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        A.start();
        B.start();
    }
}
